package cn.bsuc.crm.controller;


import cn.bsuc.crm.dto.PlanDTO;
import cn.bsuc.crm.entity.CusDevPlan;
import cn.bsuc.crm.entity.SaleChance;
import cn.bsuc.crm.service.CusDevPlanService;
import cn.bsuc.crm.util.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhuoyuan
 * @since 2022-10-03
 */
@RestController
@RequestMapping("/plan")
@CrossOrigin
public class CusDevPlanController {

    @Autowired
    private CusDevPlanService cusDevPlanService;

    @GetMapping("/selectPlanById")
    public Result selectChanceById(Integer id) {
        QueryWrapper<CusDevPlan> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("sale_chance_id",id);
        List<CusDevPlan> list = cusDevPlanService.list(objectQueryWrapper);
        return Result.ok(list);
    }

    @GetMapping("/selectPlanId")
    public Result selectPlanId(Integer id) {
        CusDevPlan byId = cusDevPlanService.getById(id);
        return Result.ok(byId);
    }

    @PostMapping("/savePlan")
    public Result savePlan(@RequestBody PlanDTO planDTO) {
        System.out.println(planDTO);
        int i = cusDevPlanService.savePlan(planDTO);
        return Result.ok();
    }

    @GetMapping("/deletePlan")
    public Result deletePlan(Integer id) {
        boolean b = cusDevPlanService.removeById(id);
        return Result.ok();
    }
}

